package jssam;

import java.awt.Component;
import java.awt.Cursor;
import java.awt.Toolkit;
import java.io.File;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.UIManager;

/**
 *
 * @author sebastien roux
 * @mail roux.sebastien@gmail.com
 *
 */
public class GUI extends javax.swing.JFrame {

    /* Set system default look&feel */
    public static void setNativeLookAndFeel() {
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (Exception e) {
            System.out.println("Error setting native LAF: " + e);
        }
    }
    private Component frame;

    /** Creates new form GUI */
    public GUI() {
        setNativeLookAndFeel();

        //Set the frame icon to an image loaded from a file.
        setIconImage(Toolkit.getDefaultToolkit().getImage(
                GUI.class.getResource("img/misc.png")));

        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jButton4 = new javax.swing.JButton();
        buttonGroup1 = new javax.swing.ButtonGroup();
        buttonGroup2 = new javax.swing.ButtonGroup();
        buttonGroup3 = new javax.swing.ButtonGroup();
        buttonGroup4 = new javax.swing.ButtonGroup();
        jButton3 = new javax.swing.JButton();
        jButton5 = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        radDateISO = new javax.swing.JRadioButton();
        radDateUS = new javax.swing.JRadioButton();
        radDateEur = new javax.swing.JRadioButton();
        radDateDefault = new javax.swing.JRadioButton();
        jPanel2 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        txtDirectoryPath = new javax.swing.JTextField();
        butonSelectDir = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        txtOutputFilePath = new javax.swing.JTextField();
        butonSelectOuputFile = new javax.swing.JButton();
        jPanel4 = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        txtFilter = new javax.swing.JTextField();
        jPanel3 = new javax.swing.JPanel();
        radSortNone = new javax.swing.JRadioButton();
        radSortAsc = new javax.swing.JRadioButton();
        radSortDesc = new javax.swing.JRadioButton();
        jPanel5 = new javax.swing.JPanel();
        chkZip = new javax.swing.JCheckBox();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();
        jMenu3 = new javax.swing.JMenu();
        jMenuItem3 = new javax.swing.JMenuItem();
        jMenuItem4 = new javax.swing.JMenuItem();
        jMenu2 = new javax.swing.JMenu();
        jMenuItem2 = new javax.swing.JMenuItem();

        jButton4.setText("jButton4");
        jButton4.setName("jButton4"); // NOI18N

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("SSAudit Merger");
        setResizable(false);

        jButton3.setText("Execute");
        jButton3.setName("buttonExecute"); // NOI18N
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                execute(evt);
            }
        });

        jButton5.setText("Quit");
        jButton5.setName("buttonQuit"); // NOI18N
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                quit(evt);
            }
        });

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Date format"));
        jPanel1.setName("panDate"); // NOI18N

        buttonGroup1.add(radDateISO);
        radDateISO.setText("ISO 8601 (YYYY-MM-DD)");
        radDateISO.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        radDateISO.setName("radDateISO"); // NOI18N

        buttonGroup1.add(radDateUS);
        radDateUS.setText("US (MM/DD/YYYY)");
        radDateUS.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        radDateUS.setName("radDateUS"); // NOI18N

        buttonGroup1.add(radDateEur);
        radDateEur.setText("European (DD/MM/YYYY)");
        radDateEur.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        radDateEur.setName("radDateEur"); // NOI18N

        buttonGroup1.add(radDateDefault);
        radDateDefault.setSelected(true);
        radDateDefault.setText("Default");
        radDateDefault.setName("radDateDefault"); // NOI18N

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(radDateDefault, javax.swing.GroupLayout.DEFAULT_SIZE, 220, Short.MAX_VALUE)
                    .addComponent(radDateISO, javax.swing.GroupLayout.DEFAULT_SIZE, 220, Short.MAX_VALUE)
                    .addComponent(radDateUS, javax.swing.GroupLayout.DEFAULT_SIZE, 220, Short.MAX_VALUE)
                    .addComponent(radDateEur))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(radDateDefault, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(radDateISO)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(radDateUS)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(radDateEur))
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Source and target"));
        jPanel2.setName("panFiles"); // NOI18N

        jLabel1.setText("Source directory");
        jLabel1.setName("labSourceFile"); // NOI18N

        txtDirectoryPath.setToolTipText("Select input directory where *.atg and *.alg files are located"); // NOI18N
        txtDirectoryPath.setName("txtDirectoryPath"); // NOI18N

        butonSelectDir.setText("...");
        butonSelectDir.setName("buttonSelectDir"); // NOI18N
        butonSelectDir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                butonSelectDirActionPerformed(evt);
            }
        });

        jLabel2.setText("Target file");
        jLabel2.setName("labTargeFile"); // NOI18N

        txtOutputFilePath.setToolTipText("Specify output file"); // NOI18N
        txtOutputFilePath.setName("txtOutputFilePath"); // NOI18N

        butonSelectOuputFile.setText("...");
        butonSelectOuputFile.setName("buttonSelectOuputFile"); // NOI18N
        butonSelectOuputFile.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                butonSelectOuputFileActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addGap(2, 2, 2)
                                .addComponent(txtOutputFilePath, javax.swing.GroupLayout.PREFERRED_SIZE, 315, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(txtDirectoryPath))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(butonSelectOuputFile, javax.swing.GroupLayout.DEFAULT_SIZE, 47, Short.MAX_VALUE)
                            .addComponent(butonSelectDir, 0, 0, Short.MAX_VALUE))
                        .addContainerGap())
                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 135, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE)))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtDirectoryPath, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(butonSelectDir, 0, 0, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel2)
                .addGap(4, 4, 4)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(butonSelectOuputFile, 0, 0, Short.MAX_VALUE)
                    .addComponent(txtOutputFilePath))
                .addContainerGap(25, Short.MAX_VALUE))
        );

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder("Filtering"));
        jPanel4.setName("panFilter"); // NOI18N

        jLabel3.setText("Filter string (case sensitive)");
        jLabel3.setName("jLabel3"); // NOI18N

        txtFilter.setToolTipText("Specify a filter string");
        txtFilter.setName("txtFilter"); // NOI18N

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, 206, Short.MAX_VALUE)
                    .addComponent(txtFilter, javax.swing.GroupLayout.DEFAULT_SIZE, 206, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addComponent(jLabel3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(txtFilter, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Sort input files by date"));
        jPanel3.setName("jPanel3"); // NOI18N

        buttonGroup2.add(radSortNone);
        radSortNone.setSelected(true);
        radSortNone.setText("Default");
        radSortNone.setName("radSortNone"); // NOI18N

        buttonGroup2.add(radSortAsc);
        radSortAsc.setText("Ascendant");
        radSortAsc.setName("radSortAsc"); // NOI18N

        buttonGroup2.add(radSortDesc);
        radSortDesc.setText("Descendant");
        radSortDesc.setName("radSortDesc"); // NOI18N

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(radSortNone, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(radSortDesc, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(radSortAsc, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(63, Short.MAX_VALUE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addComponent(radSortNone)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(radSortAsc)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(radSortDesc)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder("Compression"));
        jPanel5.setEnabled(false);
        jPanel5.setName("jPanel5"); // NOI18N

        chkZip.setText("Zip output");
        chkZip.setEnabled(false);
        chkZip.setName("chkZip"); // NOI18N
        chkZip.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                chkZipItemStateChanged(evt);
            }
        });

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(chkZip, javax.swing.GroupLayout.DEFAULT_SIZE, 146, Short.MAX_VALUE)
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addComponent(chkZip, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jMenuBar1.setName("Menu"); // NOI18N

        jMenu1.setText("File");
        jMenu1.setName("jMenu1"); // NOI18N

        jMenuItem1.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_Q, java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem1.setText("Exit");
        jMenuItem1.setName("jMenuItem1"); // NOI18N
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuFileExit(evt);
            }
        });
        jMenu1.add(jMenuItem1);

        jMenuBar1.add(jMenu1);

        jMenu3.setText("Options");
        jMenu3.setName("jMenu3"); // NOI18N

        jMenuItem3.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem3.setText("Save current configuration");
        jMenuItem3.setName("jMenuItem3"); // NOI18N
        jMenuItem3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuOptionsSaveConfig(evt);
            }
        });
        jMenu3.add(jMenuItem3);

        jMenuItem4.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_L, java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem4.setText("Load saved configuration");
        jMenuItem4.setName("jMenuItem4"); // NOI18N
        jMenuItem4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuOptionsLoadConfig(evt);
            }
        });
        jMenu3.add(jMenuItem4);

        jMenuBar1.add(jMenu3);

        jMenu2.setText("Help");
        jMenu2.setName("jMenu2"); // NOI18N

        jMenuItem2.setText("About");
        jMenuItem2.setName("jMenuItem2"); // NOI18N
        jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuHelpAbout(evt);
            }
        });
        jMenu2.add(jMenuItem2);

        jMenuBar1.add(jMenu2);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(10, 10, 10)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jPanel5, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(18, 18, 18)
                                .addComponent(jButton3)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 22, Short.MAX_VALUE)
                                .addComponent(jButton5)))))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jButton3)
                            .addComponent(jButton5)))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void butonSelectDirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_butonSelectDirActionPerformed

        String path = null;
        //Create a file chooser
        if (!txtDirectoryPath.getText().toString().isEmpty()) {
            path = txtDirectoryPath.getText().toString();
        }
        final JFileChooser dirChooser = new JFileChooser(path);
        dirChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);

        int returnVal = dirChooser.showOpenDialog(null);

        if (returnVal == JFileChooser.APPROVE_OPTION) {
            File inputDir = dirChooser.getSelectedFile();
            txtDirectoryPath.setText(inputDir.toString());
        }
}//GEN-LAST:event_butonSelectDirActionPerformed

    @SuppressWarnings("static-access")
    private void execute(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_execute
        Core core = new Core();

        // Set input directory
        if (!new File(txtDirectoryPath.getText().toString()).isDirectory()) {
            if (txtDirectoryPath.getText().toString().length() == 0) {
                //custom title, warning icon
                JOptionPane.showMessageDialog(frame,
                        "Please specify an input directory!",
                        "Input directory",
                        JOptionPane.WARNING_MESSAGE);
                return;
            } else {
                //custom title, warning icon
                JOptionPane.showMessageDialog(frame,
                        txtDirectoryPath.getText().toString() + " : directory does not exist!",
                        "Input directory",
                        JOptionPane.WARNING_MESSAGE);
                return;
            }
        } else {
            core.setInputDir(txtDirectoryPath.getText().toString());
        }

        // Set output directory
        if (txtOutputFilePath.getText().toString().isEmpty()) {
            //custom title, warning icon
            JOptionPane.showMessageDialog(frame,
                    "Please specify an output file",
                    "Output file",
                    JOptionPane.WARNING_MESSAGE);
            return;
        } else {
            core.setOutputFile(txtOutputFilePath.getText().toString());
        }

        // Set filter string
        core.setFilter(txtFilter.getText().toString());

        // Date format
        if (radDateDefault.isSelected()) {
            core.setDateFormat("default");
        } else if (radDateISO.isSelected()) {
            core.setDateFormat("iso");
        } else if (radDateEur.isSelected()) {
            core.setDateFormat("eur");
        } else if (radDateUS.isSelected()) {
            core.setDateFormat("us");
        } else {
            //custom title, warning icon
            JOptionPane.showMessageDialog(frame,
                    "No date format specified",
                    "Date format",
                    JOptionPane.WARNING_MESSAGE);
            return;
        }

        // Sort order
        if (radSortNone.isSelected()) {
            core.setSortOrder("none");
        } else if (radSortAsc.isSelected()) {
            core.setSortOrder("asc");
        } else if (radSortDesc.isSelected()) {
            core.setSortOrder("desc");
        } else {
            //custom title, warning icon
            JOptionPane.showMessageDialog(frame,
                    "No sort order specified",
                    "Sort order",
                    JOptionPane.WARNING_MESSAGE);
            return;
        }

        // Compression
        if (chkZip.isSelected()) {
            core.setZipOption(true);
        }

        setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
        core.go();
        setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
    }//GEN-LAST:event_execute

    private void quit(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_quit
        System.exit(0);
    }//GEN-LAST:event_quit

    private void butonSelectOuputFileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_butonSelectOuputFileActionPerformed

        //Create a file saver
        final JFileChooser fileSaver = new JFileChooser();
        fileSaver.setFileSelectionMode(JFileChooser.SAVE_DIALOG);

        int returnVal = fileSaver.showSaveDialog(null);

        if (returnVal == JFileChooser.APPROVE_OPTION) {
            File outputFile = fileSaver.getSelectedFile();
            txtOutputFilePath.setText(outputFile.toString());
        }
    }//GEN-LAST:event_butonSelectOuputFileActionPerformed

    private void menuFileExit(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuFileExit
        System.exit(0);
}//GEN-LAST:event_menuFileExit

    private void menuHelpAbout(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuHelpAbout
        About about = new About(this, rootPaneCheckingEnabled);
        about.setVisible(true);
}//GEN-LAST:event_menuHelpAbout

    @SuppressWarnings("static-access")
    private void menuOptionsSaveConfig(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuOptionsSaveConfig
        Config cfg = new Config();
        Core core = new Core();

        core.setInputDir(txtDirectoryPath.getText().toString());
        core.setOutputFile(txtOutputFilePath.getText().toString());
        core.setFilter(txtFilter.getText().toString());

        // Date format
        if (radDateDefault.isSelected()) {
            core.setDateFormat("default");
        } else if (radDateISO.isSelected()) {
            core.setDateFormat("iso");
        } else if (radDateEur.isSelected()) {
            core.setDateFormat("eur");
        } else if (radDateUS.isSelected()) {
            core.setDateFormat("us");
        }

        // Sort order
        if (radSortNone.isSelected()) {
            core.setSortOrder("default");
        } else if (radSortAsc.isSelected()) {
            core.setSortOrder("asc");
        } else if (radSortDesc.isSelected()) {
            core.setSortOrder("desc");
        }

        // Compression
   /*     if (chkZip) {
        core.setZipOption(true);
        } else {
        core.setZipOption(false);
        }*/

        Config.setConfig();
    }//GEN-LAST:event_menuOptionsSaveConfig

    @SuppressWarnings("static-access")
    private void menuOptionsLoadConfig(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuOptionsLoadConfig
        Core core = new Core();
        Config cfg = new Config();

        cfg.getConfig();

        txtDirectoryPath.setText(core.getInputDir().toString());
        txtOutputFilePath.setText(core.getOutputFile().toString());
        txtFilter.setText(core.getFilter().toString());

        // Date format
        if (core.getDateFormat().equals("default")) {
            radDateDefault.setSelected(true);
        } else if (core.getDateFormat().equals("iso")) {
            radDateISO.setSelected(true);
        } else if (core.getDateFormat().equals("eur")) {
            radDateEur.setSelected(true);
        } else if (core.getDateFormat().equals("us")) {
            radDateUS.setSelected(true);
        }

        // Sort order
        if (core.getSortOrder().equals("default")) {
            radSortNone.setSelected(true);
        } else if (core.getSortOrder().equals("asc")) {
            radSortAsc.setSelected(true);
        } else if (core.getSortOrder().equals("desc")) {
            radSortDesc.setSelected(true);
        }

        chkZip.setSelected(core.getZipOption());
    }//GEN-LAST:event_menuOptionsLoadConfig

    @SuppressWarnings("static-access")
    private void chkZipItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_chkZipItemStateChanged
        Core core = new Core();

        if (evt.getStateChange() == evt.DESELECTED) {
            core.setZipOption(false);
        } else {
            core.setZipOption(true);
        }
    }//GEN-LAST:event_chkZipItemStateChanged

    /**
     * @param args the command line arguments
     */
    public static void go() {
        java.awt.EventQueue.invokeLater(new Runnable() {

            @SuppressWarnings("static-access")
            public void run() {
                new GUI().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton butonSelectDir;
    private javax.swing.JButton butonSelectOuputFile;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.ButtonGroup buttonGroup2;
    private javax.swing.ButtonGroup buttonGroup3;
    private javax.swing.ButtonGroup buttonGroup4;
    private javax.swing.JCheckBox chkZip;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenu jMenu3;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JMenuItem jMenuItem3;
    private javax.swing.JMenuItem jMenuItem4;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JRadioButton radDateDefault;
    private javax.swing.JRadioButton radDateEur;
    private javax.swing.JRadioButton radDateISO;
    private javax.swing.JRadioButton radDateUS;
    private javax.swing.JRadioButton radSortAsc;
    private javax.swing.JRadioButton radSortDesc;
    private javax.swing.JRadioButton radSortNone;
    private javax.swing.JTextField txtDirectoryPath;
    private javax.swing.JTextField txtFilter;
    private javax.swing.JTextField txtOutputFilePath;
    // End of variables declaration//GEN-END:variables
}
